package b3.widget.vip
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.widget.basic.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class VipNewPlayerDialog extends BasicWidget
	{
		private const newPlayerPresent:Array = ["500_1", "314_1", "320_1"];
		
		public function VipNewPlayerDialog()
		{
			super();
			//对话框背景
			var VipNewPlayerDialogBgr:Class = ResourceHelper.getInstance().getClassByName("VipNewPlayerDialogBgr");
			addChild(new VipNewPlayerDialogBgr());
			//关闭按钮
			var VipButtonClose1:Class = ResourceHelper.getInstance().getClassByName("VipButtonClose1");
			var VipButtonClose2:Class = ResourceHelper.getInstance().getClassByName("VipButtonClose2");
			var closeIcon:ImgSwitchIcon = new ImgSwitchIcon(VipButtonClose1, VipButtonClose2);
			closeIcon.x = 490;
			closeIcon.y = 15;
			addChild(closeIcon);
			closeIcon.addEventListener(MouseEvent.CLICK, onButtonCloseClick);
			var me:Player = PlayerManager.getInstance().me;
			var presentContainer:Sprite = new Sprite();
			//礼物
			for (var i:int = 0; i < newPlayerPresent.length; i++)
			{
				var presentStr:Array = newPlayerPresent[i].split("_");
				var objectIndex:int = presentStr[0];
				var objectNum:int = presentStr[1];
				var objectConfig:ObjConfig = Config.objConfigs[objectIndex];
				var ObjectImage:Class = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage[0]);
				var objectItem:Sprite = new ObjectImage();
				objectItem.width = 100;
				objectItem.scaleY = objectItem.scaleX;
				objectItem.x = i * 140;
				presentContainer.addChild(objectItem);
				//标题名字
				var titleText:TextField = new TextField();
				titleText.selectable = false;
	        	titleText.autoSize = TextFieldAutoSize.LEFT;
				titleText.text = objectConfig.name;
				if (titleText.text.length > 6)
				{
					titleText.setTextFormat(new TextFormat("微软雅黑", 14, 0xF9F744, true));
				}
				else
				{
					titleText.setTextFormat(new TextFormat("微软雅黑", 15, 0xF9F744, true));
				}
				titleText.filters = [new GlowFilter(0x8F470E, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				titleText.x = i * 140 + 50 - titleText.width / 2;
				titleText.y = 105;
				presentContainer.addChild(titleText);
				//个数名字
				var numText:TextField = new TextField();
				numText.selectable = false;
	        	numText.autoSize = TextFieldAutoSize.LEFT;
	        	numText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0xF9F744, true);
				numText.text = "× " + objectNum;
				numText.filters = [new GlowFilter(0x8F470E, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				numText.x = i * 140 + 50 - numText.width / 2;
				numText.y = 125;
				presentContainer.addChild(numText);
				//锁
				if (!(me.is_yellow_vip || me.is_yellow_year_vip))
				{
					var VipLock:Class = ResourceHelper.getInstance().getClassByName("VipLock");
					var lock:Sprite = new VipLock();
					lock.width = 40;
					lock.scaleY = lock.scaleX;
					lock.x = i * 140 - 10;
					lock.y = -20;
					presentContainer.addChild(lock);
				}
			}
			presentContainer.mouseChildren = false;
			presentContainer.x = (this.width - presentContainer.width) / 2;
			presentContainer.y = 140;
			addChild(presentContainer);
			//顶部
			var topTitleText:TextField = new TextField();
			topTitleText.selectable = false;
        	topTitleText.autoSize = TextFieldAutoSize.LEFT;
			topTitleText.defaultTextFormat = new TextFormat("微软雅黑", 16, 0x8F470E, true);
			topTitleText.y = 95;
			addChild(topTitleText);
			//底部
			var bottomTitleText:TextField = new TextField();
			bottomTitleText.selectable = false;
        	bottomTitleText.autoSize = TextFieldAutoSize.LEFT;
			bottomTitleText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0xA77E5C, true);
			bottomTitleText.width = 200;
			bottomTitleText.text = "此外，你每天还将获得黄钻等级礼包，等级越高礼包越大。\n更有黄钻活动特权、升级双倍奖励、全场商品8折等特权让你享乐不停！";
			bottomTitleText.x = (this.width - bottomTitleText.width) / 2;
			bottomTitleText.y = 315;
			addChild(bottomTitleText);
			if (me.is_yellow_vip || me.is_yellow_year_vip)
			{
				topTitleText.text = "您是黄钻贵族，我们为您准备了以下大礼包";
				topTitleText.x = (this.width - topTitleText.width) / 2;
				//立即领取
				var VipButtonFetch:Class = ResourceHelper.getInstance().getClassByName("VipButtonFetch");
				var fetchButton:BasicButton = new BasicButton(VipButtonFetch);
				fetchButton.x = 160;
				fetchButton.y = 404;
				fetchButton.addEventListener(MouseEvent.CLICK, onButtonFectchClick);
				addChild(fetchButton);
				//续费黄钻
				var vipButtonResume:VipButtonResume = new VipButtonResume();
				vipButtonResume.x = 290;
				vipButtonResume.y = 400;
				addChild(vipButtonResume);
			}
			else
			{
				topTitleText.text = "成为黄钻贵族，即可获得以下大礼包";
				topTitleText.x = (this.width - topTitleText.width) / 2;
				var VipButtonOK:Class = ResourceHelper.getInstance().getClassByName("VipButtonOK");
				var buttonOK:BasicButton = new BasicButton(VipButtonOK);
				buttonOK.x = 160;
				buttonOK.y = 404;
				buttonOK.addEventListener(MouseEvent.CLICK, onButtonCloseClick);
				addChild(buttonOK);
				//开通黄钻
				var vipButtonOpen:VipButtonOpen = new VipButtonOpen();
				vipButtonOpen.x = 290;
				vipButtonOpen.y = 400;
				addChild(vipButtonOpen);
			}
			this.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			this.x = - this.width / 2;
			this.y = - this.height / 2;
		}
		
		private function onButtonFectchClick(event:MouseEvent):void
		{
			var me:Player = PlayerManager.getInstance().me;
			me.fetchNewPlayerPresent();
			close();
		}
		
		private function onButtonCloseClick(event:MouseEvent):void
		{
			close();
		}
		
	}
}